# 多无人机 每台种一块 6x6 有间隔
# 18M/min

from utils import *

clear()

def pick_start_pos(l):
    # '''每块南瓜田的左下角'''
    pumpkin_len = 6
    unit_size = pumpkin_len + 1
    pos = []
    for i in range(l):
        for j in range(l):
            if (i % unit_size) == 0 and (j % unit_size) == 0:
                pos.append((i,j))
    return pos


area_len_num = 4 # 一边有几个区块
l = area_len_num*(6+1)-1

set_world_size(l)

def do_task(t):
    x0,y0 = t
    pumpkin_len = 6
    
    def action(x,y):
        map.append((x,y))
        if get_ground_type() != Grounds.Soil:
            till()
        plant(Entities.Pumpkin)
        pourwater(.25)
    
    while 1:
        map = []
        snake_traverse(l,x0,y0,x0+pumpkin_len-1,y0+pumpkin_len-1,action)
        round = 0
        while 1:
            round += 1
            growing_map = []
            for pos in map:
                goto(l,pos[0],pos[1])
                if not can_harvest():
                    plant(Entities.Pumpkin)
                    growing_map.append(pos)
                    if round > 1:
                        pourwater(.75)
                    
            map = growing_map
            if len(map) == 0:
                harvest()
                round = 0
                break

all_start_pos = pick_start_pos(l)
for pos in all_start_pos[1:]:
    spawn_drone(create_task(do_task, pos))
while 1:
    do_task(all_start_pos[0])
